package com.wyl.wyl.testapplication.utils.request;

import android.app.ProgressDialog;
import android.content.Context;

import com.inossem_library.request.http.constant.RetrofitCallBackError;
import com.inossem_library.request.http.util.RetrofitCallback;
import com.inossem_library.tips.toast.util.ToastUtils;
import com.wyl.wyl.testapplication.bean.BaseBean;
import com.wyl.wyl.testapplication.constant.RetrofitConstant;

import retrofit2.Response;

/**
 * 自定义Callback
 *
 * @author 詹建宇
 * @time on 2018/11/15 16:15
 * @email jianyu.zhan@inossem.com
 */
public abstract class RequestCallback<T extends BaseBean> extends RetrofitCallback<T> {

    private Context context;

    public RequestCallback(Context context) {
        super(new ProgressDialog(context));
        this.context = context;
    }

    //请求成功
    public abstract void success(Response<T> response);

    //请求失败(业务逻辑向)
    public void failure(Response<T> response) {
//        ToastUtils.show(context, response.body().getHead().getMsg());
    }

    @Override
    public void succ(Response<T> response) {
        switch (response.body().getHead().getStatus()) {
            case RetrofitConstant.SUCCESS:
                success(response);
                break;
            default:
                failure(response);
                break;
        }
    }

    @Override
    public void httpE(Response<T> response) {
//        ToastUtils.show(context, response.body().getHead().getMsg());
        failure(response);
    }

    @Override
    public void fail(RetrofitCallBackError error) {
//        ToastUtils.show(context, error.getErrorMSgCN());
        failure(null);
//        failure(response);
    }

}
